<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/header.jsp" %>
<div class="row">
	<div class="col-xs-12">	
		<form id="customerForm" name="customerForm" class="form-horizontal" role="form">
				<input type="hidden" id="wtCustId" name="wtCustId" class="col-xs-10  input-pk " value="${customer.wtCustId}" />
				<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="wtCustName">客户姓名:<font color="red">*</font></label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="wtCustName" name="wtCustName" class="col-xs-10  can-modify" value="${customer.wtCustName}" autocomplete="off" />
					    </div>
					</div>
				</div>
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="wtCustCardno">身份证号码:</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="wtCustCardno" name="wtCustCardno" class="col-xs-10  can-modify" value="${customer.wtCustCardno}" autocomplete="off"/>
					    </div>
					</div>
				</div>
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="wtCustGender">性别:<font color="red">*</font></label>
					<div class="col-sm-9">
						<div class="clearfix">
								<select class="col-xs-10 can-modify" id="wtCustGender" name="wtCustGender">
                           			<hw:dictOption dictType="D00003" value="${customer.wtCustGender}" defaultValue="2"/>
                        		</select>
					    </div>
					</div>
				</div>
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="wtCustPhone">联系电话:</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="wtCustPhone" name="wtCustPhone" class="col-xs-10  can-modify" value="${customer.wtCustPhone}" autocomplete="off"/>
					    </div>
					</div>
				</div>
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="wtCustAddress">家庭住址:</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="wtCustAddress" name="wtCustAddress" class="col-xs-10  can-modify" value="${customer.wtCustAddress}" autocomplete="off"/>
					    </div>
					</div>
				</div>
				<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="wtCustWorkAddress">工作单位:</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="wtCustWorkAddress" name="wtCustWorkAddress" class="col-xs-10  can-modify" value="${customer.wtCustWorkAddress}" autocomplete="off"/>
					    </div>
					</div>
				</div>
				<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="wtCustIntention">客户意向:</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="wtCustIntention" name="wtCustIntention" class="col-xs-10  can-modify" value="${customer.wtCustIntention}" autocomplete="off"/>
					    </div>
					</div>
				</div>
				<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="wtPlanId">所属计划:</label>
					<div class="col-sm-9">
						<div class="clearfix">
							<c:choose>
								<c:when test="${flag == 'add'}">
									<select id="wtPlanId" name="wtPlanId"  class="col-xs-10 can-modify">
										<option value="">===请选择===</option>
		                       			<c:forEach var="planList" items="${planList}">
		                       				<c:choose>
		                       					<c:when test="${planList.wtPlanId == customer.wtPlanId}">
		                       						<option value="${planList.wtPlanId}" selected>${planList.wtPlanTitle}</option>
		                       					</c:when>
		                       					<c:otherwise>
		                       						<option value="${planList.wtPlanId}">${planList.wtPlanTitle}</option>
		                       					</c:otherwise>
		                       				</c:choose>
			                       		</c:forEach>  
		                    		</select>
		                    	</c:when>
							<c:otherwise>
								<input type="text" id="wtPlanTitle" name="wtPlanTitle" class="col-xs-10  can-modify" value="${customer.wtPlanTitle}" autocomplete="off"/>
							</c:otherwise>
	                        </c:choose>
					    </div>
					</div>
				</div>
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="wtCustToUser">所属客户经理:<font color="red">*</font></label>
					<div class="col-sm-9">
						<div class="clearfix">
							<c:choose>
								<c:when test="${flag == 'add'}">
									<select id="wtCustToUser" name="wtCustToUser"  class="col-xs-10 can-modify">
		                       		  	<c:forEach var="userList" items="${userList}">
			                       		 	<c:choose>
			                       		 		<c:when test="${userList.userId == customer.wtCustToUser}">
										           	<option value="${userList.userId}"  selected>${userList.userName}</option>
										    	</c:when>
										    	<c:otherwise>
										           	<option value="${userList.userId}">${userList.userName}</option>
										        </c:otherwise>
			                           		</c:choose>
		                       			</c:forEach> 
		                    		</select>					     
							   	</c:when>
							   	<c:otherwise>
							   		<input type="text" id="wtCustToUserName" name="wtCustToUserName" class="col-xs-10  can-modify" value="${customer.wtCustToUserName}" autocomplete="off"/>
							    </c:otherwise>
	                        </c:choose>
					    </div>
					</div>
				</div>
				<div class="form-group" id="createUserDiv">	
					<label class="col-sm-3 control-label no-padding-right" for="createUser">录入人员</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="createUser" name="createUser" class="col-xs-10 " value="${customer.createUser}" disabled/>
					    </div>
					</div>
				</div>
				<div class="form-group" id="createTimeDiv">	
					<label class="col-sm-3 control-label no-padding-right" for="createTime">录入时间</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="createTime" name="createTime" class="col-xs-10 " value="${customer.createTime}" disabled/>
					    </div>
					</div>
				</div>
				<div class="form-group" id="updateUserDiv">	
					<label class="col-sm-3 control-label no-padding-right" for="updateUser">更新人员</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="updateUser" name="updateUser" class="col-xs-10 " value="${customer.updateUser}" disabled/>
					    </div>
					</div>
				</div>
				<div class="form-group" id="updateTimeDiv" >	
					<label class="col-sm-3 control-label no-padding-right" for="updateTime">更新时间</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="updateTime" name="updateTime" class="col-xs-10 " value="${customer.updateTime}" disabled/>
					    </div>
					</div>
				</div>
		</form>
	</div>		
</div>
<script type="text/javascript">

var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	if ("${flag}" != "add") {
		disabledAll("customerForm");			
	} 
	
	//~~~~~~~~~~~~~~~~~ 动态验证证件类型和证件号  START~~~~~~~~~~~~~
	/* $('#wtCustCardno').on('change', function () {
		$("#wtCustCardno").removeData("previousValue"); 
		$("#wtCustCardno").valid();
    }); */
	//~~~~~~~~~~~~~~~~~ 动态验证证件类型和证件号  END ~~~~~~~~~~~~~
	
	$('#customerForm').validate({
		errorElement: 'div',
		errorClass: 'help-block',
		focusInvalid: false,
		ignore: "",
		rules: {
			wtCustName: {
		       required: true,
		       stringMaxLength:30
		    },
			wtCustPhone:{
		    	digits:true
			},
			wtCustToUser: {
		       required: true
			},
			wtPlanId:{
			   required: true
			}
		},
		messages: {
			wtCustName: {
			   required: "客户姓名不能为空"
	    	},
			wtCustToUser: {
			   required: "所属客户经理不能为空"
			},
			wtPlanId:{
			   required: "所属计划不能为空"
			}
		},
		submitHandler: function (form) {
		},
		invalidHandler: function (form) {
		}
	});
	
});


function initButtons() {
	if ("${flag}" == "add") {
		$("#btnCustomerModify").hide();
		$("#btnCustomerSave").show();
		$("#btnCustomerDelete").hide();
		$("#btnCustomerCancle").hide();
		$("#btnCustomerClose").show();
		
		$("#createUserDiv").hide();
		$("#createTimeDiv").hide();
		$("#updateUserDiv").hide();
		$("#updateTimeDiv").hide();
	} else {
		$("#btnCustomerModify").show();
		$("#btnCustomerSave").hide();
		$("#btnCustomerDelete").show();
		$("#btnCustomerCancle").hide();
		$("#btnCustomerClose").show();	
	}

}

function cancle() {
	initButtons();
	disabledAll("customerForm");
}

function modify() {
	enabledAll("customerForm");
	$("#btnCustomerModify").hide();
	$("#btnCustomerSave").show();
	$("#btnCustomerDelete").hide();
	$("#btnCustomerCancle").show();
	$("#btnCustomerClose").show();
		
	//$("#wtCustToUser").attr("disabled",true);
	$("#createUser").attr("disabled",true);
    $("#createTime").attr("disabled",true);
    $("#updateUser").attr("disabled",true);
    $("#updateTime").attr("disabled",true);	
    $("#wtCustToUser").attr("disabled",true);
    $("#wtCustToUserName").attr("disabled",true);
    $("#wtPlanId").attr("disabled",true);
    $("#wtPlanTitle").attr("disabled",true);
    $("#wtCustToUser").rules("remove");
    $("#wtPlanId").rules("remove");
}


function save() {
	if(!$("#customerForm").valid()){
		return;		
	}
	var url;
	if ("${flag}" == "add") {
		url = "${ctx}/customer/add.do";
	}else {
		url = "${ctx}/customer/modify.do";
	}
	$.ajax({
		async : false,
		url: url,
		type:"post",
		data: $("#customerForm").serialize(),
		dataType:"json",
		success: function(ret){	
			if (ret[0] == "ok") {
				alert(ret[1]);
				$("#customerIframe").dialog("close");
				$("#customerIframe").empty();
				$("#searchCustomer").click();
			} else {
				alert(ret[1]);
				$("#wtCustToUser").attr("disabled",true);
				$("#createUser").attr("disabled",true);
			    $("#createTime").attr("disabled",true);
			    $("#updateUser").attr("disabled",true);
			    $("#updateTime").attr("disabled",true);	
			}				
		},
		error: function(ret){
			alert(ret.responseText);
			disabledAll("customerForm");
		}
	}); 
}

</script>